package com.itheima.service;


import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;

    //分页查询
    public PageResult findPage(QueryPageBean queryPageBean) {
        //获取参数
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        //用mybatis分页助手
        PageHelper.startPage(currentPage, pageSize);
        Page<Permission> pages = permissionDao.findByCondition(queryString);
        //返回查询结果
        long total = pages.getTotal();
        List<Permission> rows = pages.getResult();
        return new PageResult(total, rows);
    }

    //新建权限
    public void add(Permission permission) {
        permissionDao.add(permission);

    }

    //删除权限
    public void delete(Integer id) {
        permissionDao.delete(id);

    }

    //编辑权限,根据id查询回显数据
    public Permission findById(Integer id) {
        return permissionDao.findById(id);

    }

    //将修改权限后的表单数据提交并保存
    public void updateById(Permission permission) {
        permissionDao.updateById(permission);

    }

}